class Snake {
    constructor() {
        this.element = document.querySelector('#snake');
        this.head = document.querySelector('#snake>div'); //只取第一个表示蛇头
        this.bodies = this.element.getElementsByTagName('div');
    }
    //获取蛇头的位置
    get X() {
        return this.head.offsetLeft;
    }
    get Y() {
        return this.head.offsetTop;
    }
    //设置蛇头的位置
    set X(value) {
        this.head.style.left = value + 'px';
    }
    set Y(value) {
        this.head.style.top = value + 'px';
    }
    //增加身体
    addBody() {
        this.element.insertAdjacentHTML("beforeend", "<div></div>"); //添加一个元素至结尾
    }
}
export default Snake;
